// call 要实现的要素
// 接收两个参数，把函数this指向第一个参数，第二个参数为函数所需的

Function.prototype.myCall = function(target, ...args) {
    if(typeof this !== 'function') {
        throw new Error('Type error')
    }
    target = target || window;
    const symbleKey = Symbol();
    target[symbleKey] = this;
    const res = target[symbleKey](...args);
    delete target[symbleKey]
    return res
}

Function.prototype.myApply = function(target, args) {
    target = target || window;
    let res = null;
    const symbleKey = Symbol();
    target[symbleKey] = this;
    res = target[symbleKey](...args);
    delete target[symbleKey];
    return res
}

const obj = {
    value: '对象值'
}
const msg = {
    value: '原对象',
    sex: '男',
    fn(name, age) {
        console.log(`${this.value},我的名字是${name}, 年龄是${age}`)
    },
    say() {
        console.log(this.value)
    }
}
msg.myApply(obj, ['zk', 18])
// console.log(msg.fn)
// msg.fn.apply(obj, ['zz', 18])
// msg.say.myCall(this)
// console.log(obj)

